home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / drdobbs / 1991 / 06 / tsr.asc < prev   
Text File  |  1991-05-02  |  7KB  |  219 lines

  1. _TAKING UP RESIDENCE WITH CODERUNNER_
  2. by R. Bradley Andrews
  3.  
  4.  
  5. [LISTING ONE]
  6.  
  7. #include "cr.h"
  8.  
  9. /** RESIDENT CODE STACK SPACE **/
  10. #define HK_STK 150      /* Stack size for Hot-Key services */
  11. #define SR_STK 64       /* Stack for COM services */
  12. #define STK_SZ (HK_STK+SR_STK)  /* Size in words */
  13. word isr_stk[STK_SZ+1]; /* Allow allways extra word ! */
  14.  
  15. extern popclock();  /* Main TSR entry, called by scheduler */
  16.  
  17. extern hk_isr();    /* Hot-Key service in HELLO.C */
  18. extern word hk_list[];  /* This is in HELLOINI.C for use by isr() function */
  19.  
  20. /******** Disposable messages in MSICLDAT.C **************/
  21. extern char sms[];       /* Signon screen                */
  22. extern char attrc[],attrm[]; /* Screen attributes used for signon */
  23. extern char already[];       /* Message when already loaded      */
  24. extern char unloaddone[];
  25. extern char unloadproblem[];
  26. extern word init_data_end;   /* Marker for end of disposable data */
  27.  
  28. /* Dummy function marks start of disposable code  */
  29. init_code_start()
  30. {
  31. }
  32.  
  33.  
  34. /* this main is called only once on program load, after that it is discarded */
  35. main()
  36. {  int i;
  37.    char *a;
  38.  
  39.     if(second_load())   /* Check if TSR already loaded */
  40.         {
  41.         i=str_pos('-',cmd_line);
  42.         if (i && ((cmd_line[i]|0x20)=='r'))
  43.             {
  44.             if(remove_tsr())    /* Remove TSR from memory */
  45.                 {
  46.                 dspf(unloaddone); /* Inform about unloading */
  47.                 }
  48.             else dspf(unloadproblem); /* Inform about unloading */
  49.             }
  50.             else dspf(already); /* Otherwise show Help message */
  51.             mv_crs();   /* Reposition real cursor */
  52.             return(1);  /* Exit with errorlevel 1 */
  53.          }
  54.  
  55.  /***** Display Signon Screen *****/
  56.     clr_scr();
  57.     a = color ? attrc:attrm; /* Select proper screen attributes */
  58.     crs_x=20; crs_y=7;   /* Location to put signon box      */
  59.     dspf(sms,a);         /* Show the screen                 */
  60.  
  61.     crs_x=0; crs_y=scr_len-2; /* Move to the bottom of screen    */
  62.     mv_crs();         /* Place real cursor there         */
  63.     crs_y=0;          /* Top line used to display clock  */
  64.  
  65.   idata_end=&init_data_end;     /* This enables init data disposal. */
  66.   icode_beg=init_code_start;        /* This enables init code disposal. */
  67.  
  68.   stay_resident(isr_stk,STK_SZ*2);  /* Enable resident mode             */
  69.   install_hk(hk_list,hk_isr,STK_SZ*2,0x7F); /* HOT-KEY Support */
  70.  
  71.   install_tsc(popclock,2*STK_SZ,1); /* Install tiny scheduler           */
  72. /*  add_tsc_event(8L);      /* Add event to timer, 8 ticks from now  */
  73.                 /* Popclock will be called by scheduler  */
  74.   return(0);            /* Set errorlevel to 0                   */
  75.  
  76. }
  77.  
  78.  
  79.  
  80. [LISTING TWO]
  81.  
  82. /* this module contains ALL disposable data only.  The marker at the end
  83.    called init_end_data is just a marker to the end of disposable data
  84.    NO CODE CAN BE PUT INTO THIS MODULE, DATA ONLY */
  85.  
  86. #include "cr.h"
  87.  
  88. /* Video attributes for signon screen. The last one is for the Clock */
  89.  
  90. /*char attrc[]={0x17,0x1E,0x13,0x1F,0x1B,0x17}; /* Color screen attributes */
  91. /*char attrm[]={0x07,0x0F,0x07,0x07,0x07,0x70}; /* Mono screen attributes  */
  92.  
  93. /* This is the signon message */
  94. char sms[]= "`0"
  95.         "[_________________________[`m"
  96.         "[`1       Timer 1.00        `0[`m"
  97.         "[`2      DDDDDDDDDDD        `0[`m"
  98.         "[`4        Author:          `0[`m"
  99.         "[`4   R. Bradley Andrews    `0[`m"
  100.         "[\\\\\\\\\\\\\\\\\\\\\\\\\[`n`5";
  101.  
  102. char already[]="`nError - Timer already present."
  103.                "`nEnter MSICLOCK -R to unload.`n";
  104. word hk_list[]={M_RS+0x44,0}; /* Right-Shift Enter  */
  105.  
  106. char unloaddone[]="Timer has been removed from memory.`n";
  107. char unloadproblem[]="Timer could not be removed from memory.";
  108. char _tsr_name[]="Timer";
  109.  
  110. struct cfg_rec config_block = { /* This record stays in only one module */
  111.     sizeof(config_block),   /* Configuration block size */
  112.     'T','I','M','E',    /* Program ID string */
  113.     100,            /* Version 1.00 */
  114.     };
  115.  
  116. /****  STORE THIS IMMEDIATELY AFTER THE LAST DISPOSABLE DATA ITEM ****/
  117.  
  118. /****  1. Store all install_?? type function pointers into install_list ****/
  119. fp install_list[]={install_tsc, install_hk, install_bk};  /* Only tiny scheduler used */
  120.  
  121. /****  2. Put Marker for the end-of-init-data (must be = NONZERO) ****/
  122. word init_data_end=1;
  123. /************************************************************************/
  124.  
  125.  
  126.  
  127. [LISTING THREE]
  128.  
  129. #include "cr.h"
  130.  
  131. /** RESIDENT CODE STACK SPACE **/
  132. #define HK_STK 150      /* Stack size for Hot-Key services */
  133. #define SR_STK 100      /* Stack for COM services */
  134. #define STK_SZ (HK_STK+SR_STK)  /* Size in words */
  135.  
  136. #define kWidth  13      /* width of display string */
  137.  
  138. char time_str[]=" 00:00:00:00 ";
  139. char blank_str[]="             ";
  140.  
  141. word sbuf[kWidth];
  142.  
  143. char attrc[]={0x17,0x1E,0x13,0x1F,0x1B,0x17}; /* Color screen attributes */
  144. char attrm[]={0x07,0x0F,0x07,0x07,0x07,0x70}; /* Mono screen attributes  */
  145.  
  146. long start_ticks;
  147.  
  148. int which=0;
  149.  
  150. popclock(void)
  151. {  register char *t,*s;
  152.     register long cur_ticks;
  153.    struct time_rec cur_time;
  154.  
  155.     if (which==1) {
  156.         add_tsc_event(1L);  /* Setup next event in 1/3 second */
  157.     }
  158.     cur_ticks = bios_ticks();
  159.     cur_ticks = cur_ticks - start_ticks;
  160.     ticks2time(cur_ticks, &cur_time);
  161.  
  162.     t=&cur_time.hours;  /* Prepare to convert hh:mm:ss */
  163.     s=time_str+1;
  164.     do cv_b2dec((byte)*t,s), s+=3;     /* Convert 1 byte to decimal */
  165.       while (--t>=&cur_time.sec100);  /* Until done with seconds */
  166.  
  167.     chk_video();          /* Obtain current video settings */
  168.     crs_x=scr_width-kWidth;   /* Set cursor to upper right corner */
  169.     dsp(time_str);        /* Display time string there */
  170.  
  171. }
  172. hk_isr()
  173.     if (!which) {
  174.         crs_x=scr_width-kWidth;   /* Set cursor to upper right corner */
  175.         get_block(kWidth,1,sbuf);
  176.         start_ticks = bios_ticks();
  177.         add_tsc_event(1L);      /* Add event to timer, 8 ticks from now  */
  178.         which++;
  179.     }
  180.     else    {
  181.         if (which == 1 ) {
  182.             which++;
  183.         }
  184.         else {
  185.             crs_x=scr_width-kWidth;   /* Set cursor to upper right corner */
  186.             put_block(kWidth,1,sbuf);
  187.             which = 0;
  188.         }
  189.     }
  190. }
  191.  
  192.  
  193.  
  194.  
  195. [LISTING FOUR]
  196.  
  197. REM  Use switch  d   for debug mode
  198. REM
  199. if %1x==dx goto compdebug
  200. tcc -c -I..\ -DPDK1 timer*.c
  201. goto linkit
  202. rem
  203. :compdebug
  204. tcc -c -v -I..\ -DDBG timer*.c
  205. :linkit
  206. del timerini.lib
  207. lib timerini +timerini;
  208. if %1x==dx goto dbg
  209. :lnk1
  210. link ..\r0 timerdat timer ..\r1,timer,,..\k1 ..\cr  timerini/NOI/NOD/M;
  211. goto exit
  212. :dbg
  213. tlink ..\r0 timerdat timer ..\r1,timer,,..\cr  timerini/c/m/v;
  214. :exit
  215.  
  216.  
  217.  
  218.